{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e194b32e",
   "metadata": {},
   "source": [
    "# 课堂_分组柱状图_数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e57f1162",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1002\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  const force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  const JS_MIME_TYPE = 'application/javascript';\n",
       "  const HTML_MIME_TYPE = 'text/html';\n",
       "  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  const CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    const script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    const cell = handle.cell;\n",
       "\n",
       "    const id = cell.output_area._bokeh_element_id;\n",
       "    const server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd_clean, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            const id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd_destroy);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    const output_area = handle.output_area;\n",
       "    const output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      const bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      const script_attrs = bk_div.children[0].attributes;\n",
       "      for (let i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      const toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    const events = require('base/js/events');\n",
       "    const OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  const NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    const el = document.getElementById(\"1002\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error(url) {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < css_urls.length; i++) {\n",
       "      const url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < js_urls.length; i++) {\n",
       "      const url = js_urls[i];\n",
       "      const element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n",
       "  const css_urls = [];\n",
       "  \n",
       "\n",
       "  const inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (let i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    const el = document.getElementById(\"1002\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n  const css_urls = [];\n  \n\n  const inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(\"1002\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e43ba225",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from bokeh.models import ColumnDataSource, CustomJSTransform, FactorRange\n",
    "from bokeh.plotting import figure\n",
    "from bokeh.io import output_file, show\n",
    "from bokeh.transform import transform\n",
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6, Spectral3\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2616fe06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('week08_data.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e98b6217",
   "metadata": {},
   "source": [
    "## 准备x轴坐标数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7bd72901",
   "metadata": {},
   "outputs": [],
   "source": [
    "# object -> list: tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "247c597e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Visualization_tools', 'Watch', 'Star', 'Fork', 'Commits',\n",
       "       'Contributors'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9574b2c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Visualization_tools', 'Watch', 'Star', 'Fork', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9010fcfe",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 元组常常在数据科学中用于 malti  复合数据（分组数据/多个层级的数据）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e21daa6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Star', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 二级数据准备 ---对应 示例代码年份数据 （） （元组的第二个位置）\n",
    "vis_tools_categroy = [df.columns.tolist()[2],df.columns.tolist()[4],df.columns.tolist()[5]]\n",
    "vis_tools_categroy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "25a33824",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 一级数据准备  （元组的第一个位置）\n",
    "df['Visualization_tools']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6da88419",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列表推倒式准备x轴 多级数据\n",
    "x = [(tool,categrogy) for tool in df['Visualization_tools'] for categrogy in vis_tools_categroy]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "583509d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3032943b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('matplotlib', 'Star'),\n",
       " ('matplotlib', 'Commits'),\n",
       " ('matplotlib', 'Contributors'),\n",
       " ('bokeh', 'Star'),\n",
       " ('bokeh', 'Commits'),\n",
       " ('bokeh', 'Contributors'),\n",
       " ('pyecharts', 'Star'),\n",
       " ('pyecharts', 'Commits'),\n",
       " ('pyecharts', 'Contributors'),\n",
       " ('seaborn', 'Star'),\n",
       " ('seaborn', 'Commits'),\n",
       " ('seaborn', 'Contributors'),\n",
       " ('plotly', 'Star'),\n",
       " ('plotly', 'Commits'),\n",
       " ('plotly', 'Contributors'),\n",
       " ('ggplot2', 'Star'),\n",
       " ('ggplot2', 'Commits'),\n",
       " ('ggplot2', 'Contributors')]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e246cbc",
   "metadata": {},
   "source": [
    "## 准备y轴数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b88af476",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<zip at 0x14fd02f8308>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zip(df['Star'], df['Commits'], df['Contributors'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b2eeea02",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 分组求和(堆叠总数)\n",
    "y = sum(zip(df['Star'], df['Commits'], df['Contributors']), ()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "720bf024",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(9678, 29503, 808, 11034, 17673, 357, 5387, 1321, 18, 6038, 2316, 98, 4928, 3370, 76, 3783, 4286, 184)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(y)\n",
    "len(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "d89a4faf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('#99d594', '#ffffbf', '#fc8d59')"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral3\n",
    "Spectral3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4d347b8b",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"13abada9-b15c-43d5-a545-7f9605fd0928\" data-root-id=\"1005\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"ca085f47-0049-4873-9875-49c24df05950\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1015\"}],\"center\":[{\"id\":\"1017\"},{\"id\":\"1021\"}],\"height\":350,\"left\":[{\"id\":\"1018\"}],\"renderers\":[{\"id\":\"1043\"}],\"title\":{\"id\":\"1006\"},\"toolbar\":{\"id\":\"1030\"},\"x_range\":{\"id\":\"1004\"},\"x_scale\":{\"id\":\"1011\"},\"y_range\":{\"id\":\"1009\"},\"y_scale\":{\"id\":\"1013\"}},\"id\":\"1005\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1051\",\"type\":\"AllLabels\"},{\"attributes\":{\"data\":{\"x_axis\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"y_counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184]},\"selected\":{\"id\":\"1053\"},\"selection_policy\":{\"id\":\"1052\"}},\"id\":\"1003\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1025\",\"type\":\"SaveTool\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"1004\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1050\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"tools\":[{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"},{\"id\":\"1025\"},{\"id\":\"1026\"},{\"id\":\"1027\"},{\"id\":\"1029\"}]},\"id\":\"1030\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1047\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1048\",\"type\":\"AllLabels\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"1038\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"y_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x_axis\"}},\"id\":\"1041\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1017\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1052\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"\\u53ef\\u89c6\\u5316\\u6a21\\u5757\\u5728github\\u7684\\u4f7f\\u7528\\u6570\\u636e\"},\"id\":\"1006\",\"type\":\"Title\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"#99d594\",\"#ffffbf\",\"#fc8d59\"],\"start\":1},\"id\":\"1038\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{\"start\":0},\"id\":\"1009\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"PanTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1028\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"1003\"}},\"id\":\"1044\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1018\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1021\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1011\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1028\"}},\"id\":\"1024\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1053\",\"type\":\"Selection\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1047\"},\"group\":null,\"major_label_policy\":{\"id\":\"1048\"},\"ticker\":{\"id\":\"1019\"}},\"id\":\"1018\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1013\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1027\",\"type\":\"HelpTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"counts\",\"@y_counts\"],[\"tools\",\"@x_axis\"]]},\"id\":\"1029\",\"type\":\"HoverTool\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1050\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"1051\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"1038\"}},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"y_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x_axis\"}},\"id\":\"1040\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1026\",\"type\":\"ResetTool\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1003\"},\"glyph\":{\"id\":\"1040\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1042\"},\"nonselection_glyph\":{\"id\":\"1041\"},\"view\":{\"id\":\"1044\"}},\"id\":\"1043\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"1038\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"y_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x_axis\"}},\"id\":\"1042\",\"type\":\"VBar\"}],\"root_ids\":[\"1005\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"ca085f47-0049-4873-9875-49c24df05950\",\"root_ids\":[\"1005\"],\"roots\":{\"1005\":\"13abada9-b15c-43d5-a545-7f9605fd0928\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1005"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.transform import factor_cmap\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x_axis = x,\n",
    "        y_counts = y,     \n",
    "    )\n",
    ")\n",
    "color = Spectral3\n",
    "# 点击数据 tooltips\n",
    "TOOLTIPS = [\n",
    "    (\"counts\",\"@y_counts\"),\n",
    "    (\"tools\",\"@x_axis\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=FactorRange(*x),\n",
    "    plot_height=350,\n",
    "    title=\"可视化模块在github的使用数据\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "# 绘制图形 vbar 垂直柱状图\n",
    "p.vbar(\n",
    "    x='x_axis',\n",
    "    top=\"y_counts\",\n",
    "    width=0.8,\n",
    "    source=source,\n",
    "    fill_color=factor_cmap('x_axis', palette=color, factors=vis_tools_categroy, start=1, end=2)\n",
    ")\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22d402f9",
   "metadata": {},
   "source": [
    "# 985院校数据，尝试分组柱状图、折线图、散点图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a4f394ad",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>账号名称</th>\n",
       "      <th>认证名称</th>\n",
       "      <th>抖音号</th>\n",
       "      <th>简介</th>\n",
       "      <th>获赞数_int</th>\n",
       "      <th>粉丝数_int</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>清华大学</td>\n",
       "      <td>清华大学官方抖音号</td>\n",
       "      <td>Tsinghua1911</td>\n",
       "      <td>自强不息 厚德载物在这里你将看到不一样的清华大学</td>\n",
       "      <td>28768000</td>\n",
       "      <td>7156000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>北京大学</td>\n",
       "      <td>北京大学官方抖音号</td>\n",
       "      <td>PKU_1898</td>\n",
       "      <td>直播预告：3.15 15:00 中国经济观察3.16 19:00古代希腊的英雄主义3.17 ...</td>\n",
       "      <td>32159000</td>\n",
       "      <td>6267000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>国防科技大学</td>\n",
       "      <td>国防科技大学官方抖音号</td>\n",
       "      <td>1979202900</td>\n",
       "      <td>厚德博学，强军兴国投稿邮箱：nudtdy@qq.com</td>\n",
       "      <td>63277000</td>\n",
       "      <td>4230000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>浙江大学</td>\n",
       "      <td>浙江大学官方账号</td>\n",
       "      <td>zju1897</td>\n",
       "      <td>求是 创新在这里记录不一样的浙大</td>\n",
       "      <td>36419000</td>\n",
       "      <td>1746000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>武汉大学</td>\n",
       "      <td>武汉大学官方抖音</td>\n",
       "      <td>luojia1893</td>\n",
       "      <td>珞珈之山 东湖之水 山高水长 流风甚美投稿邮箱：whuvideo@163.com</td>\n",
       "      <td>16573000</td>\n",
       "      <td>1310000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>上海交通大学</td>\n",
       "      <td>上海交通大学官方抖音账号</td>\n",
       "      <td>SJTU</td>\n",
       "      <td>饮水思源，爱国荣校。投稿及联系邮箱：zxyzaa-0210@sjtu.edu.cn</td>\n",
       "      <td>12331000</td>\n",
       "      <td>1112000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>复旦大学</td>\n",
       "      <td>复旦大学官方抖音</td>\n",
       "      <td>FDU1905</td>\n",
       "      <td>博学而笃志 切问而近思</td>\n",
       "      <td>3094000</td>\n",
       "      <td>1037000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>北京师范大学</td>\n",
       "      <td>北京师范大学官方抖音号</td>\n",
       "      <td>bnu1902</td>\n",
       "      <td>咦，被你发现了！</td>\n",
       "      <td>5942000</td>\n",
       "      <td>941000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>华中科技大学</td>\n",
       "      <td>华中科技大学官方账号</td>\n",
       "      <td>hust_1952</td>\n",
       "      <td>华中大官抖，带你了解不一样的华中科技大学</td>\n",
       "      <td>13734000</td>\n",
       "      <td>881000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>中国人民大学</td>\n",
       "      <td>中国人民大学官方账号</td>\n",
       "      <td>RUC1937</td>\n",
       "      <td>国民表率 社会栋梁</td>\n",
       "      <td>9373000</td>\n",
       "      <td>866000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>西安交通大学</td>\n",
       "      <td>西安交通大学</td>\n",
       "      <td>XJTU521</td>\n",
       "      <td>承继百廿南洋道统 弘扬甲子西迁精神合作投稿请私信</td>\n",
       "      <td>2038000</td>\n",
       "      <td>571000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>厦门大学</td>\n",
       "      <td>厦门大学官方抖音号</td>\n",
       "      <td>XMU19210406</td>\n",
       "      <td>自强不息 止于至善欢迎投稿:tvtg@xmu.edu.cn</td>\n",
       "      <td>3453000</td>\n",
       "      <td>551000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>北京航空航天大学</td>\n",
       "      <td>北京航空航天大学官方抖音号</td>\n",
       "      <td>Beihang1952</td>\n",
       "      <td>德才兼备，知行合一</td>\n",
       "      <td>4954000</td>\n",
       "      <td>454000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>南开大学</td>\n",
       "      <td>南开大学官方抖音号</td>\n",
       "      <td>NKU19191017</td>\n",
       "      <td>允公允能，日新月异公共投稿邮箱：Nankaidouyin@163.com</td>\n",
       "      <td>5691000</td>\n",
       "      <td>448000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>吉林大学</td>\n",
       "      <td>吉林大学官方抖音账号</td>\n",
       "      <td>JLU1946</td>\n",
       "      <td>求实创新，励志图强我就是那个有六个校区，而且特别特别大的“双一流”、“985工程”高校～投稿...</td>\n",
       "      <td>12336000</td>\n",
       "      <td>443000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>四川大学</td>\n",
       "      <td>四川大学官方抖音号</td>\n",
       "      <td>SCU1896</td>\n",
       "      <td>岷峨挺秀，锦水含章；巍巍学府，德渥群芳。你好，这里是四川大学。校园视频投稿：scuxmtlm...</td>\n",
       "      <td>5151000</td>\n",
       "      <td>394000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>山东大学</td>\n",
       "      <td>山东大学官方抖音号</td>\n",
       "      <td>1901SDU</td>\n",
       "      <td>学无止境，气有浩然欢迎来稿：sdunmc@sdu.edu.cn（投稿可私信）</td>\n",
       "      <td>3780000</td>\n",
       "      <td>345000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>天津大学</td>\n",
       "      <td>天津大学官方抖音号</td>\n",
       "      <td>tianda1895</td>\n",
       "      <td>中国第一所现代大学欢迎投稿 tjutv1895@163.com</td>\n",
       "      <td>1722000</td>\n",
       "      <td>314000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>东南大学</td>\n",
       "      <td>东南大学官方抖音账号</td>\n",
       "      <td>Seu190266</td>\n",
       "      <td>985 211 “双一流”建设A类高校</td>\n",
       "      <td>4762000</td>\n",
       "      <td>284000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>电子科技大学</td>\n",
       "      <td>电子科技大学官方抖音</td>\n",
       "      <td>UESTC1956</td>\n",
       "      <td>求实求真  大气大为</td>\n",
       "      <td>1090000</td>\n",
       "      <td>268000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>大连理工大学</td>\n",
       "      <td>大连理工大学官方账号</td>\n",
       "      <td>iduter</td>\n",
       "      <td>讲述大工故事 传递大工声音 交流师生感悟 凝聚爱校情怀</td>\n",
       "      <td>2520000</td>\n",
       "      <td>267000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>兰州大学</td>\n",
       "      <td>兰州大学官方抖音号</td>\n",
       "      <td>LZU1909</td>\n",
       "      <td>自强不息，独树一帜</td>\n",
       "      <td>3147000</td>\n",
       "      <td>254000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>同济大学</td>\n",
       "      <td>同济大学官方抖音号</td>\n",
       "      <td>Tongji_1907</td>\n",
       "      <td>同心同德同舟楫 济人济事济天下我是同济，请给我比心吧</td>\n",
       "      <td>1609000</td>\n",
       "      <td>238000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>华东师范大学</td>\n",
       "      <td>华东师范大学官方抖音号</td>\n",
       "      <td>ecnu</td>\n",
       "      <td>求实创造，为人师表。公众投稿及联系邮箱：ecnuxcb@admin.ecnu.edu.cn</td>\n",
       "      <td>1943000</td>\n",
       "      <td>230000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>湖南大学</td>\n",
       "      <td>湖南大学官方抖音号</td>\n",
       "      <td>HNU1926</td>\n",
       "      <td>实事求是 敢为人先</td>\n",
       "      <td>2203000</td>\n",
       "      <td>222000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>重庆大学</td>\n",
       "      <td>重庆大学官方抖音号</td>\n",
       "      <td>cqdx19291012</td>\n",
       "      <td>耐劳苦 尚俭朴 勤学业 爱国家投稿邮箱 video@yuxiaowei.cn</td>\n",
       "      <td>749000</td>\n",
       "      <td>184000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>中南大学</td>\n",
       "      <td>中南大学官方抖音</td>\n",
       "      <td>CSU0429</td>\n",
       "      <td>知行合一    经世致用向善求真    唯美有容融入中南大学，实现人生理想。公众投稿及联系邮...</td>\n",
       "      <td>1853000</td>\n",
       "      <td>179000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>西北工业大学</td>\n",
       "      <td>西北工业大学官方抖音号</td>\n",
       "      <td>npustar</td>\n",
       "      <td>欢迎投稿：291884513@qq.com</td>\n",
       "      <td>325000</td>\n",
       "      <td>144000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>中国科学技术大学</td>\n",
       "      <td>中国科学技术大学</td>\n",
       "      <td>ustcnews</td>\n",
       "      <td>创寰宇学府 育天下英才</td>\n",
       "      <td>937000</td>\n",
       "      <td>118000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>中国农业大学</td>\n",
       "      <td>中国农业大学官方</td>\n",
       "      <td>CAU1905</td>\n",
       "      <td>中国农业大学官方</td>\n",
       "      <td>58000</td>\n",
       "      <td>110000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>西北农林科技大学</td>\n",
       "      <td>西北农林科技大学官方抖音账号</td>\n",
       "      <td>NWAFU1934</td>\n",
       "      <td>诚朴勇毅        经国本，解民生，尚科学欢迎各位西农er投稿（一经采纳会有小礼物哦）：...</td>\n",
       "      <td>1358000</td>\n",
       "      <td>103000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>北京理工大学</td>\n",
       "      <td>北京理工大学官方抖音号</td>\n",
       "      <td>BIT_1940</td>\n",
       "      <td>德以明理，学以精工。</td>\n",
       "      <td>996000</td>\n",
       "      <td>98000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>中国海洋大学</td>\n",
       "      <td>中国海洋大学官方抖音账号</td>\n",
       "      <td>OUC1924</td>\n",
       "      <td>海纳百川，取则行远。hey这里是小海，欢迎来撩~</td>\n",
       "      <td>504000</td>\n",
       "      <td>88000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>哈尔滨工业大学</td>\n",
       "      <td>哈尔滨工业大学官方抖音</td>\n",
       "      <td>iHIT1920</td>\n",
       "      <td>在这里，你将看到不一样的哈工大</td>\n",
       "      <td>139000</td>\n",
       "      <td>83000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>华南理工大学</td>\n",
       "      <td>华南理工大学官方抖音号</td>\n",
       "      <td>SCUT1952</td>\n",
       "      <td>博学慎思 明辨笃行</td>\n",
       "      <td>76000</td>\n",
       "      <td>76000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>中央民族大学</td>\n",
       "      <td>中央民族大学官方账号</td>\n",
       "      <td>MUC1951</td>\n",
       "      <td>美美与共，知行合一。</td>\n",
       "      <td>356000</td>\n",
       "      <td>62000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>南京大学</td>\n",
       "      <td>南京大学抖音官方账号</td>\n",
       "      <td>44494962529</td>\n",
       "      <td>南京大学抖音官方账号投稿邮箱:media@nju.edu.cn</td>\n",
       "      <td>84000</td>\n",
       "      <td>59000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>东北大学</td>\n",
       "      <td>东北大学官方抖音账号</td>\n",
       "      <td>NEU_1923</td>\n",
       "      <td>自强不息，知行合一投稿&amp;联系我们：3554513629@qq.com</td>\n",
       "      <td>474000</td>\n",
       "      <td>41000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        账号名称            认证名称           抖音号  \\\n",
       "0       清华大学       清华大学官方抖音号  Tsinghua1911   \n",
       "1       北京大学       北京大学官方抖音号      PKU_1898   \n",
       "2     国防科技大学     国防科技大学官方抖音号    1979202900   \n",
       "3       浙江大学        浙江大学官方账号       zju1897   \n",
       "4       武汉大学        武汉大学官方抖音    luojia1893   \n",
       "5     上海交通大学    上海交通大学官方抖音账号          SJTU   \n",
       "6       复旦大学        复旦大学官方抖音       FDU1905   \n",
       "7     北京师范大学     北京师范大学官方抖音号       bnu1902   \n",
       "8     华中科技大学      华中科技大学官方账号     hust_1952   \n",
       "9     中国人民大学      中国人民大学官方账号       RUC1937   \n",
       "10    西安交通大学          西安交通大学       XJTU521   \n",
       "11      厦门大学       厦门大学官方抖音号   XMU19210406   \n",
       "12  北京航空航天大学   北京航空航天大学官方抖音号   Beihang1952   \n",
       "13      南开大学       南开大学官方抖音号   NKU19191017   \n",
       "14      吉林大学      吉林大学官方抖音账号       JLU1946   \n",
       "15      四川大学       四川大学官方抖音号       SCU1896   \n",
       "16      山东大学       山东大学官方抖音号       1901SDU   \n",
       "17      天津大学       天津大学官方抖音号    tianda1895   \n",
       "18      东南大学      东南大学官方抖音账号     Seu190266   \n",
       "19    电子科技大学      电子科技大学官方抖音     UESTC1956   \n",
       "20    大连理工大学      大连理工大学官方账号        iduter   \n",
       "21      兰州大学       兰州大学官方抖音号       LZU1909   \n",
       "22      同济大学       同济大学官方抖音号   Tongji_1907   \n",
       "23    华东师范大学     华东师范大学官方抖音号          ecnu   \n",
       "24      湖南大学       湖南大学官方抖音号       HNU1926   \n",
       "25      重庆大学       重庆大学官方抖音号  cqdx19291012   \n",
       "26      中南大学        中南大学官方抖音       CSU0429   \n",
       "27    西北工业大学     西北工业大学官方抖音号       npustar   \n",
       "28  中国科学技术大学        中国科学技术大学      ustcnews   \n",
       "29    中国农业大学        中国农业大学官方       CAU1905   \n",
       "30  西北农林科技大学  西北农林科技大学官方抖音账号     NWAFU1934   \n",
       "31    北京理工大学     北京理工大学官方抖音号      BIT_1940   \n",
       "32    中国海洋大学    中国海洋大学官方抖音账号       OUC1924   \n",
       "33   哈尔滨工业大学     哈尔滨工业大学官方抖音      iHIT1920   \n",
       "34    华南理工大学     华南理工大学官方抖音号      SCUT1952   \n",
       "35    中央民族大学      中央民族大学官方账号       MUC1951   \n",
       "36      南京大学      南京大学抖音官方账号   44494962529   \n",
       "37      东北大学      东北大学官方抖音账号      NEU_1923   \n",
       "\n",
       "                                                   简介   获赞数_int  粉丝数_int  \n",
       "0                            自强不息 厚德载物在这里你将看到不一样的清华大学  28768000  7156000  \n",
       "1   直播预告：3.15 15:00 中国经济观察3.16 19:00古代希腊的英雄主义3.17 ...  32159000  6267000  \n",
       "2                         厚德博学，强军兴国投稿邮箱：nudtdy@qq.com  63277000  4230000  \n",
       "3                                    求是 创新在这里记录不一样的浙大  36419000  1746000  \n",
       "4            珞珈之山 东湖之水 山高水长 流风甚美投稿邮箱：whuvideo@163.com  16573000  1310000  \n",
       "5           饮水思源，爱国荣校。投稿及联系邮箱：zxyzaa-0210@sjtu.edu.cn  12331000  1112000  \n",
       "6                                         博学而笃志 切问而近思   3094000  1037000  \n",
       "7                                            咦，被你发现了！   5942000   941000  \n",
       "8                                华中大官抖，带你了解不一样的华中科技大学  13734000   881000  \n",
       "9                                           国民表率 社会栋梁   9373000   866000  \n",
       "10                           承继百廿南洋道统 弘扬甲子西迁精神合作投稿请私信   2038000   571000  \n",
       "11                      自强不息 止于至善欢迎投稿:tvtg@xmu.edu.cn   3453000   551000  \n",
       "12                                          德才兼备，知行合一   4954000   454000  \n",
       "13               允公允能，日新月异公共投稿邮箱：Nankaidouyin@163.com   5691000   448000  \n",
       "14  求实创新，励志图强我就是那个有六个校区，而且特别特别大的“双一流”、“985工程”高校～投稿...  12336000   443000  \n",
       "15  岷峨挺秀，锦水含章；巍巍学府，德渥群芳。你好，这里是四川大学。校园视频投稿：scuxmtlm...   5151000   394000  \n",
       "16             学无止境，气有浩然欢迎来稿：sdunmc@sdu.edu.cn（投稿可私信）   3780000   345000  \n",
       "17                    中国第一所现代大学欢迎投稿 tjutv1895@163.com   1722000   314000  \n",
       "18                                985 211 “双一流”建设A类高校   4762000   284000  \n",
       "19                                         求实求真  大气大为   1090000   268000  \n",
       "20                        讲述大工故事 传递大工声音 交流师生感悟 凝聚爱校情怀   2520000   267000  \n",
       "21                                          自强不息，独树一帜   3147000   254000  \n",
       "22                         同心同德同舟楫 济人济事济天下我是同济，请给我比心吧   1609000   238000  \n",
       "23      求实创造，为人师表。公众投稿及联系邮箱：ecnuxcb@admin.ecnu.edu.cn   1943000   230000  \n",
       "24                                          实事求是 敢为人先   2203000   222000  \n",
       "25             耐劳苦 尚俭朴 勤学业 爱国家投稿邮箱 video@yuxiaowei.cn    749000   184000  \n",
       "26  知行合一    经世致用向善求真    唯美有容融入中南大学，实现人生理想。公众投稿及联系邮...   1853000   179000  \n",
       "27                              欢迎投稿：291884513@qq.com    325000   144000  \n",
       "28                                        创寰宇学府 育天下英才    937000   118000  \n",
       "29                                           中国农业大学官方     58000   110000  \n",
       "30  诚朴勇毅        经国本，解民生，尚科学欢迎各位西农er投稿（一经采纳会有小礼物哦）：...   1358000   103000  \n",
       "31                                         德以明理，学以精工。    996000    98000  \n",
       "32                           海纳百川，取则行远。hey这里是小海，欢迎来撩~    504000    88000  \n",
       "33                                    在这里，你将看到不一样的哈工大    139000    83000  \n",
       "34                                          博学慎思 明辨笃行     76000    76000  \n",
       "35                                         美美与共，知行合一。    356000    62000  \n",
       "36                    南京大学抖音官方账号投稿邮箱:media@nju.edu.cn     84000    59000  \n",
       "37                 自强不息，知行合一投稿&联系我们：3554513629@qq.com    474000    41000  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pd.read_csv('985.csv')\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "8fd35457",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['账号名称', '认证名称', '抖音号', '简介', '获赞数_int', '粉丝数_int']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8c97fc66",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('清华大学', '获赞数_int'),\n",
       " ('清华大学', '粉丝数_int'),\n",
       " ('北京大学', '获赞数_int'),\n",
       " ('北京大学', '粉丝数_int'),\n",
       " ('国防科技大学', '获赞数_int'),\n",
       " ('国防科技大学', '粉丝数_int'),\n",
       " ('浙江大学', '获赞数_int'),\n",
       " ('浙江大学', '粉丝数_int'),\n",
       " ('武汉大学', '获赞数_int'),\n",
       " ('武汉大学', '粉丝数_int'),\n",
       " ('上海交通大学', '获赞数_int'),\n",
       " ('上海交通大学', '粉丝数_int'),\n",
       " ('复旦大学', '获赞数_int'),\n",
       " ('复旦大学', '粉丝数_int'),\n",
       " ('北京师范大学', '获赞数_int'),\n",
       " ('北京师范大学', '粉丝数_int'),\n",
       " ('华中科技大学', '获赞数_int'),\n",
       " ('华中科技大学', '粉丝数_int'),\n",
       " ('中国人民大学', '获赞数_int'),\n",
       " ('中国人民大学', '粉丝数_int'),\n",
       " ('西安交通大学', '获赞数_int'),\n",
       " ('西安交通大学', '粉丝数_int'),\n",
       " ('厦门大学', '获赞数_int'),\n",
       " ('厦门大学', '粉丝数_int'),\n",
       " ('北京航空航天大学', '获赞数_int'),\n",
       " ('北京航空航天大学', '粉丝数_int'),\n",
       " ('南开大学', '获赞数_int'),\n",
       " ('南开大学', '粉丝数_int'),\n",
       " ('吉林大学', '获赞数_int'),\n",
       " ('吉林大学', '粉丝数_int'),\n",
       " ('四川大学', '获赞数_int'),\n",
       " ('四川大学', '粉丝数_int'),\n",
       " ('山东大学', '获赞数_int'),\n",
       " ('山东大学', '粉丝数_int'),\n",
       " ('天津大学', '获赞数_int'),\n",
       " ('天津大学', '粉丝数_int'),\n",
       " ('东南大学', '获赞数_int'),\n",
       " ('东南大学', '粉丝数_int'),\n",
       " ('电子科技大学', '获赞数_int'),\n",
       " ('电子科技大学', '粉丝数_int'),\n",
       " ('大连理工大学', '获赞数_int'),\n",
       " ('大连理工大学', '粉丝数_int'),\n",
       " ('兰州大学', '获赞数_int'),\n",
       " ('兰州大学', '粉丝数_int'),\n",
       " ('同济大学', '获赞数_int'),\n",
       " ('同济大学', '粉丝数_int'),\n",
       " ('华东师范大学', '获赞数_int'),\n",
       " ('华东师范大学', '粉丝数_int'),\n",
       " ('湖南大学', '获赞数_int'),\n",
       " ('湖南大学', '粉丝数_int'),\n",
       " ('重庆大学', '获赞数_int'),\n",
       " ('重庆大学', '粉丝数_int'),\n",
       " ('中南大学', '获赞数_int'),\n",
       " ('中南大学', '粉丝数_int'),\n",
       " ('西北工业大学', '获赞数_int'),\n",
       " ('西北工业大学', '粉丝数_int'),\n",
       " ('中国科学技术大学', '获赞数_int'),\n",
       " ('中国科学技术大学', '粉丝数_int'),\n",
       " ('中国农业大学', '获赞数_int'),\n",
       " ('中国农业大学', '粉丝数_int'),\n",
       " ('西北农林科技大学', '获赞数_int'),\n",
       " ('西北农林科技大学', '粉丝数_int'),\n",
       " ('北京理工大学', '获赞数_int'),\n",
       " ('北京理工大学', '粉丝数_int'),\n",
       " ('中国海洋大学', '获赞数_int'),\n",
       " ('中国海洋大学', '粉丝数_int'),\n",
       " ('哈尔滨工业大学', '获赞数_int'),\n",
       " ('哈尔滨工业大学', '粉丝数_int'),\n",
       " ('华南理工大学', '获赞数_int'),\n",
       " ('华南理工大学', '粉丝数_int'),\n",
       " ('中央民族大学', '获赞数_int'),\n",
       " ('中央民族大学', '粉丝数_int'),\n",
       " ('南京大学', '获赞数_int'),\n",
       " ('南京大学', '粉丝数_int'),\n",
       " ('东北大学', '获赞数_int'),\n",
       " ('东北大学', '粉丝数_int')]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cate = [df2.columns.tolist()[4],df2.columns.tolist()[5]]\n",
    "x = [(account, category) for account in df2['账号名称'] for category in cate]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "6af9ba32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(28768000, 7156000, 32159000, 6267000, 63277000, 4230000, 36419000, 1746000, 16573000, 1310000, 12331000, 1112000, 3094000, 1037000, 5942000, 941000, 13734000, 881000, 9373000, 866000, 2038000, 571000, 3453000, 551000, 4954000, 454000, 5691000, 448000, 12336000, 443000, 5151000, 394000, 3780000, 345000, 1722000, 314000, 4762000, 284000, 1090000, 268000, 2520000, 267000, 3147000, 254000, 1609000, 238000, 1943000, 230000, 2203000, 222000, 749000, 184000, 1853000, 179000, 325000, 144000, 937000, 118000, 58000, 110000, 1358000, 103000, 996000, 98000, 504000, 88000, 139000, 83000, 76000, 76000, 356000, 62000, 84000, 59000, 474000, 41000)\n"
     ]
    }
   ],
   "source": [
    "y = sum(zip(df2['获赞数_int'], df2['粉丝数_int']), ()) \n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "7c9d5476",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('#3288bd', '#99d594', '#e6f598', '#fee08b', '#fc8d59', '#d53e4f')"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Spectral6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "cceb516d",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"d83bc359-02c3-43bd-a71e-11a14ec4d1f5\" data-root-id=\"1473\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"d96f0280-507c-4d1a-8b06-941882cb596e\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1483\"}],\"center\":[{\"id\":\"1485\"},{\"id\":\"1489\"}],\"height\":500,\"left\":[{\"id\":\"1486\"}],\"renderers\":[{\"id\":\"1511\"}],\"title\":{\"id\":\"1474\"},\"toolbar\":{\"id\":\"1498\"},\"width\":2800,\"x_range\":{\"id\":\"1472\"},\"x_scale\":{\"id\":\"1479\"},\"y_range\":{\"id\":\"1477\"},\"y_scale\":{\"id\":\"1481\"}},\"id\":\"1473\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"1506\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"y_counts\"},\"x\":{\"field\":\"x_axis\"}},\"id\":\"1509\",\"type\":\"VBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1496\"}},\"id\":\"1492\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"1477\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1495\",\"type\":\"HelpTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"\\u6296\\u97f3\\u4e0a\\u7684985\\u5927\\u5b66\\u5b98\\u65b9\\u8d26\\u53f7\\u7c89\\u4e1d\\u4e0e\\u83b7\\u8d5e\\u72b6\\u51b5\"},\"id\":\"1474\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"1483\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1485\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1559\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1484\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1493\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1479\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1481\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"1506\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"y_counts\"},\"x\":{\"field\":\"x_axis\"}},\"id\":\"1510\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1471\"},\"glyph\":{\"id\":\"1508\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1510\"},\"nonselection_glyph\":{\"id\":\"1509\"},\"view\":{\"id\":\"1512\"}},\"id\":\"1511\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1558\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"1559\"},\"ticker\":{\"id\":\"1484\"}},\"id\":\"1483\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"counts\",\"@y_counts\"],[\"tools\",\"@x_axis\"]]},\"id\":\"1497\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1491\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1487\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1494\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1490\",\"type\":\"PanTool\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1555\"},\"group\":null,\"major_label_policy\":{\"id\":\"1556\"},\"ticker\":{\"id\":\"1487\"}},\"id\":\"1486\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data\":{\"x_axis\":[[\"\\u6e05\\u534e\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6e05\\u534e\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u56fd\\u9632\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u56fd\\u9632\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u6d59\\u6c5f\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6d59\\u6c5f\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u6b66\\u6c49\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6b66\\u6c49\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e0a\\u6d77\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e0a\\u6d77\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u590d\\u65e6\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u590d\\u65e6\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u5e08\\u8303\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u5e08\\u8303\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u534e\\u4e2d\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u534e\\u4e2d\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u4eba\\u6c11\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u4eba\\u6c11\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u897f\\u5b89\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u897f\\u5b89\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u53a6\\u95e8\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u53a6\\u95e8\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u822a\\u7a7a\\u822a\\u5929\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u822a\\u7a7a\\u822a\\u5929\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5357\\u5f00\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5357\\u5f00\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5409\\u6797\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5409\\u6797\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u56db\\u5ddd\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u56db\\u5ddd\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5c71\\u4e1c\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5c71\\u4e1c\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5929\\u6d25\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5929\\u6d25\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e1c\\u5357\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e1c\\u5357\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u7535\\u5b50\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u7535\\u5b50\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5927\\u8fde\\u7406\\u5de5\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5927\\u8fde\\u7406\\u5de5\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5170\\u5dde\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5170\\u5dde\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u540c\\u6d4e\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u540c\\u6d4e\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u534e\\u4e1c\\u5e08\\u8303\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u534e\\u4e1c\\u5e08\\u8303\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u6e56\\u5357\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6e56\\u5357\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u91cd\\u5e86\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u91cd\\u5e86\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u5357\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u5357\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u897f\\u5317\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u897f\\u5317\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u79d1\\u5b66\\u6280\\u672f\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u79d1\\u5b66\\u6280\\u672f\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u519c\\u4e1a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u519c\\u4e1a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u897f\\u5317\\u519c\\u6797\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u897f\\u5317\\u519c\\u6797\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u7406\\u5de5\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u7406\\u5de5\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u6d77\\u6d0b\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u6d77\\u6d0b\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u54c8\\u5c14\\u6ee8\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u54c8\\u5c14\\u6ee8\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u534e\\u5357\\u7406\\u5de5\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u534e\\u5357\\u7406\\u5de5\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u592e\\u6c11\\u65cf\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u592e\\u6c11\\u65cf\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5357\\u4eac\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5357\\u4eac\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e1c\\u5317\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e1c\\u5317\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"]],\"y_counts\":[28768000,7156000,32159000,6267000,63277000,4230000,36419000,1746000,16573000,1310000,12331000,1112000,3094000,1037000,5942000,941000,13734000,881000,9373000,866000,2038000,571000,3453000,551000,4954000,454000,5691000,448000,12336000,443000,5151000,394000,3780000,345000,1722000,314000,4762000,284000,1090000,268000,2520000,267000,3147000,254000,1609000,238000,1943000,230000,2203000,222000,749000,184000,1853000,179000,325000,144000,937000,118000,58000,110000,1358000,103000,996000,98000,504000,88000,139000,83000,76000,76000,356000,62000,84000,59000,474000,41000]},\"selected\":{\"id\":\"1561\"},\"selection_policy\":{\"id\":\"1560\"}},\"id\":\"1471\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"1506\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"y_counts\"},\"x\":{\"field\":\"x_axis\"}},\"id\":\"1508\",\"type\":\"VBar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1496\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"tools\":[{\"id\":\"1490\"},{\"id\":\"1491\"},{\"id\":\"1492\"},{\"id\":\"1493\"},{\"id\":\"1494\"},{\"id\":\"1495\"},{\"id\":\"1497\"}]},\"id\":\"1498\",\"type\":\"Toolbar\"},{\"attributes\":{\"factors\":[[\"\\u6e05\\u534e\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6e05\\u534e\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u56fd\\u9632\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u56fd\\u9632\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u6d59\\u6c5f\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6d59\\u6c5f\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u6b66\\u6c49\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6b66\\u6c49\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e0a\\u6d77\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e0a\\u6d77\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u590d\\u65e6\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u590d\\u65e6\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u5e08\\u8303\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u5e08\\u8303\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u534e\\u4e2d\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u534e\\u4e2d\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u4eba\\u6c11\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u4eba\\u6c11\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u897f\\u5b89\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u897f\\u5b89\\u4ea4\\u901a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u53a6\\u95e8\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u53a6\\u95e8\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u822a\\u7a7a\\u822a\\u5929\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u822a\\u7a7a\\u822a\\u5929\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5357\\u5f00\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5357\\u5f00\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5409\\u6797\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5409\\u6797\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u56db\\u5ddd\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u56db\\u5ddd\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5c71\\u4e1c\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5c71\\u4e1c\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5929\\u6d25\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5929\\u6d25\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e1c\\u5357\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e1c\\u5357\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u7535\\u5b50\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u7535\\u5b50\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5927\\u8fde\\u7406\\u5de5\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5927\\u8fde\\u7406\\u5de5\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5170\\u5dde\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5170\\u5dde\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u540c\\u6d4e\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u540c\\u6d4e\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u534e\\u4e1c\\u5e08\\u8303\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u534e\\u4e1c\\u5e08\\u8303\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u6e56\\u5357\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u6e56\\u5357\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u91cd\\u5e86\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u91cd\\u5e86\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u5357\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u5357\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u897f\\u5317\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u897f\\u5317\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u79d1\\u5b66\\u6280\\u672f\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u79d1\\u5b66\\u6280\\u672f\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u519c\\u4e1a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u519c\\u4e1a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u897f\\u5317\\u519c\\u6797\\u79d1\\u6280\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u897f\\u5317\\u519c\\u6797\\u79d1\\u6280\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5317\\u4eac\\u7406\\u5de5\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5317\\u4eac\\u7406\\u5de5\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u56fd\\u6d77\\u6d0b\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u56fd\\u6d77\\u6d0b\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u54c8\\u5c14\\u6ee8\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u54c8\\u5c14\\u6ee8\\u5de5\\u4e1a\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u534e\\u5357\\u7406\\u5de5\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u534e\\u5357\\u7406\\u5de5\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e2d\\u592e\\u6c11\\u65cf\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e2d\\u592e\\u6c11\\u65cf\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u5357\\u4eac\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u5357\\u4eac\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"],[\"\\u4e1c\\u5317\\u5927\\u5b66\",\"\\u83b7\\u8d5e\\u6570_int\"],[\"\\u4e1c\\u5317\\u5927\\u5b66\",\"\\u7c89\\u4e1d\\u6570_int\"]],\"range_padding\":0.01},\"id\":\"1472\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1561\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1558\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1560\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"end\":2,\"factors\":[\"\\u83b7\\u8d5e\\u6570_int\",\"\\u7c89\\u4e1d\\u6570_int\"],\"palette\":[\"#3288bd\",\"#99d594\"],\"start\":1},\"id\":\"1506\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"1555\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1486\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1489\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1471\"}},\"id\":\"1512\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1556\",\"type\":\"AllLabels\"}],\"root_ids\":[\"1473\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"d96f0280-507c-4d1a-8b06-941882cb596e\",\"root_ids\":[\"1473\"],\"roots\":{\"1473\":\"d83bc359-02c3-43bd-a71e-11a14ec4d1f5\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1473"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(data=dict(\n",
    "    x_axis = x,\n",
    "    y_counts = y,\n",
    "))\n",
    "\n",
    "color = ['#3288bd', '#99d594']\n",
    "TOOLTIPS = [\n",
    "    (\"counts\",\"@y_counts\"),\n",
    "    (\"tools\",\"@x_axis\")\n",
    "]\n",
    "\n",
    "p = figure(\n",
    "    x_range = FactorRange(*x),\n",
    "    plot_height = 500,\n",
    "    plot_width = 2800,\n",
    "    title = \"抖音上的985大学官方账号粉丝与获赞状况\",\n",
    "    tooltips = TOOLTIPS\n",
    ")\n",
    "\n",
    "p.vbar(\n",
    "    x = 'x_axis',\n",
    "    top = 'y_counts',\n",
    "    width = 1,\n",
    "    source = source,\n",
    "    line_color=\"white\",\n",
    "    fill_color = factor_cmap('x_axis', palette=color, factors=cate, start=1, end=2)\n",
    ")\n",
    "\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.01\n",
    "p.xaxis.major_label_orientation = 1\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e405618",
   "metadata": {},
   "source": [
    "# 水果数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c4023efa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"adbe781a-edde-4ab8-aecf-501cedeca93a\" data-root-id=\"1615\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"b5063a57-31c9-4b94-a3a1-7dfab59604ac\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1625\"}],\"center\":[{\"id\":\"1627\"},{\"id\":\"1631\"}],\"height\":350,\"left\":[{\"id\":\"1628\"}],\"renderers\":[{\"id\":\"1650\"}],\"title\":{\"id\":\"1616\"},\"toolbar\":{\"id\":\"1639\"},\"x_range\":{\"id\":\"1614\"},\"x_scale\":{\"id\":\"1621\"},\"y_range\":{\"id\":\"1619\"},\"y_scale\":{\"id\":\"1623\"}},\"id\":\"1615\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"start\":0},\"id\":\"1619\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1613\"},\"glyph\":{\"id\":\"1647\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1649\"},\"nonselection_glyph\":{\"id\":\"1648\"},\"view\":{\"id\":\"1651\"}},\"id\":\"1650\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1647\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1632\",\"type\":\"PanTool\"},{\"attributes\":{\"source\":{\"id\":\"1613\"}},\"id\":\"1651\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1636\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"1625\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1627\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1633\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts by Year\"},\"id\":\"1616\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"1638\"}},\"id\":\"1634\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1626\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1635\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1710\",\"type\":\"Selection\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1648\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1709\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1621\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1637\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1708\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1704\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1623\",\"type\":\"LinearScale\"},{\"attributes\":{\"tools\":[{\"id\":\"1632\"},{\"id\":\"1633\"},{\"id\":\"1634\"},{\"id\":\"1635\"},{\"id\":\"1636\"},{\"id\":\"1637\"}]},\"id\":\"1639\",\"type\":\"Toolbar\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1707\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"1708\"},\"ticker\":{\"id\":\"1626\"}},\"id\":\"1625\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1705\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1638\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1629\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1707\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1704\"},\"group\":null,\"major_label_policy\":{\"id\":\"1705\"},\"ticker\":{\"id\":\"1629\"}},\"id\":\"1628\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1649\",\"type\":\"VBar\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"1710\"},\"selection_policy\":{\"id\":\"1709\"}},\"id\":\"1613\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"1614\",\"type\":\"FactorRange\"},{\"attributes\":{\"axis\":{\"id\":\"1628\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1631\",\"type\":\"Grid\"}],\"root_ids\":[\"1615\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"b5063a57-31c9-4b94-a3a1-7dfab59604ac\",\"root_ids\":[\"1615\"],\"roots\":{\"1615\":\"adbe781a-edde-4ab8-aecf-501cedeca93a\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1615"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "\n",
    "# 分组求和(堆叠总数)\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) \n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a92af8d9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
